#coding: utf-8 
from math import sqrt

class CleanPoint():
	def __init__(self, pos, dist):
		self.pos = pos
		self.dist = dist
		self.connections=[]
		
	def connect(self,to):
		self.connections.append(to)
	
	def count(self):
		cnt=1
		for cp in self.connections:
			cnt+=cp.count()
		
		return cnt
	
	def __repr__(self):
		return 'CP - '+str(self.pos)

class CleanAreaTree():
	def __init__(self,d):
		self.d=d
		self.area=CleanArea(d)
		self.generateGraph(self.d)
		
	def generateGraph(self,d):
		def near(pos0,pos1):
			return max(abs(pos0[0]-pos1[0]),abs(pos0[1]-pos1[1]))<=1
			
		self.iCP=CleanPoint((0,0),0)
		lastStepCleanPoints=[self.iCP]
		
		for i in range(1,d+1):
			area=CleanArea(i)
			area.remove_circle(0,0,i-1)
			thisStepPoints=area.points
			thisStepCleanPoints=[]
			
			for posNew, distNew in thisStepPoints.items():
				cleanPointNew = CleanPoint(posNew,distNew)
				thisStepCleanPoints.append(cleanPointNew)
				for cleanPointOld in lastStepCleanPoints:
					if near(cleanPointOld.pos,posNew):
						cleanPointOld.connect(cleanPointNew)
			
			lastStepCleanPoints = thisStepCleanPoints
		
	def count(self):
		return self.iCP.count()
		
	
class CleanArea:
	def __init__(self,d):
		self.points={}
		self.d=d
		self.add_circle(0,0,d)
	
	
	def add_circle(self,centerx,centery,d):
		
		self.d=max(centerx+d,centerx-d,centery+d,centery-d,self.d)
		
		for y in range(-d,d+1):
			for x in range(-d,d+1):
				
				if x!=0:
					xabs=abs(x)-0.5
				else:
					xabs=0.0
					
				if y!=0:
					yabs=abs(y)-0.5
				else:
					yabs=0.0
				
				if sqrt(yabs*yabs+xabs*xabs)<=d:
					self.points[(centerx+x,centery+y)]=d-sqrt(yabs*yabs+xabs*xabs)
	
	def remove_circle(self,centerx,centery,d):
		for y in range(-d,d+1):
			for x in range(-d,d+1):
				
				if x!=0:
					xabs=abs(x)-0.5
				else:
					xabs=0.0
					
				if y!=0:
					yabs=abs(y)-0.5
				else:
					yabs=0.0
				
				if sqrt(yabs*yabs+xabs*xabs)<=d:
					point=(centerx+x,centery+y)
					if point in self.points:
						self.points.pop(point)

	def __repr__(self):
		text='\n'
		for y in range(-self.d,self.d+1):
			for x in range(-self.d,self.d+1):
				if (x,y) in self.points.keys():
					text+= 'x'
				else:
					text+=' '
			text+='\n'
		return text

if __name__=='__main__':
	#from cleanArea import *
	a=CleanAreaTree(1)
	print a.count()
